$(document).ready(function () {
    initPagination();
});

//条件查询开始
$("#distpicker1").distpicker({
    autoSelect: false
});

//条件查询结束
//表格头部字段筛选

var json = {};

var orderBy="";

$('.seek-btn').on('click',function(){
    initPagination();
});



//清空条件
$('.seek-clear').on('click', function () {
    $('#start-time').val('');
    $('#end-time').val('');
    $('#sbwybm').val('');
})

function clear() {
    $('start-time').val('');
    $('end-time').val('');
    $('sbwybm').val('');
}

$(".form-control").on("change",
    function () { }
);

//分页
function initPagination() {
    // 创建分页
    //获取总行数
    var totalcount = getCount();
    //按照下标进行查询
    $("#Pagination").pagination(totalcount, {
        num_edge_entries: 0, //边缘页数
        num_display_entries: 10, //主体页数
        callback: pageselectCallback, //回调函数
        items_per_page: 10, //每页显示10项
        prev_text: "上一页",
        next_text: "下一页",
        ellipse_text: "...",//省略的文本
        prev_show_always: true,//是否总显示“前一页”分页按钮
        next_show_always: true,//是否总显示“下一页”分页按钮，
    });
    $("#currentCount").text("总充值数量："+totalcount);
};
function pageselectCallback(page_index, jq) {
    query(page_index, jq);
}
//   表格部分 结束
function query(page_index, jq) {
    //发送 ajax;
    $.ajax(
        {
            type: "post",
            url: "/convenient/query",
            data: getJson(page_index, jq),
            dataType: "json",
            async: false,
            success: function (data) {
                var result = data.data;
                var tmpl1 = bt('list1', result);
                $("#tbody1").html(tmpl1);

            }, error: function () {
            alert("报错了");
        }
        }
    );
}

function getJson(page_index, jq) {
    var queryjson;
    queryjson = {
        startTimeFrom: $('#start-time')["0"].value,
        startTimeTo: $('#end-time')["0"].value,
        deviceNum: $('#sbwybm')["0"].value,
        pageNum: page_index + 1,
        orderBy: orderBy
    }
    return queryjson;
}

function getCount() {
    var result = 0;
    var qjson=getJson(0, 0);
    $.ajax(
        {
            type: "post",
            url: "/convenient/count",
            data: qjson,
            dataType: "json",
            async: false,
            success: function (data) {
                result = data.data;
            }, error: function () {
            alert("报错了");
        }
        }
    );
    return result;
}



function getFormatDateStr(obj){
    return  getFormatDate(obj );
}